//
//  HMHomeCell.swift
//  HMSlender
//
//  Created by 赵少朋赵少朋 on 2017/2/4.
//  Copyright © 2017年 ITheima. All rights reserved.
//

import UIKit

class HMHomeCell: UITableViewCell {

    // 记录约束
    var bottomViewTopConstraint: Constraint?
    var statusModel: HMStatusViewModel? {
    
        didSet {
            
            /// 给原创微博赋值数据
            originalView.statusModel = statusModel!
            /// 给转发微博赋值数据
            retweetView.statusModel = statusModel!
            
//            print(statusModel?.homeModle?.retweeted_status)
            //卸掉约束
            bottomViewTopConstraint?.uninstall()
            
            if statusModel?.homeModle?.retweeted_status == nil {
                //没有转发微博
                bottomView.snp_makeConstraints(closure: { (make) in
                    bottomViewTopConstraint = make.top.equalTo(originalView.snp_bottom).constraint
                })
            } else {
                
                //有转发微博
                bottomView.snp_makeConstraints(closure: { (make) in
                    bottomViewTopConstraint = make.top.equalTo(retweetView.snp_bottom).constraint
                })
            }
            
        }
    }
  
    override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        
        setupUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    func setupUI() -> Void {
        
        /// 原创微博
        contentView.addSubview(originalView)
        /// 转发微博
        contentView.addSubview(retweetView)
        /// 底部评论视图
        contentView.addSubview(bottomView)
        
        
        originalView.snp_makeConstraints { (make) in
            make.top.left.right.equalTo(contentView)
            
        }
        
        retweetView.snp_makeConstraints { (make) in
            make.top.equalTo(originalView.snp_bottom)
            make.right.equalTo(contentView)
            make.width.equalTo(contentView)
            
        }
        
        bottomView.snp_makeConstraints { (make) in
            make.left.right.equalTo(contentView)
            bottomViewTopConstraint = make.top.equalTo(retweetView.snp_bottom).constraint
            make.bottom.equalTo(contentView.snp_bottom)
            make.height.equalTo(35)
        }
        
        
    }
    
    private lazy var originalView: HMHomeOriginalView = HMHomeOriginalView()
    
    private lazy var bottomView: HMHomeBottomView = HMHomeBottomView()
    
    private lazy var retweetView:HMHomeRetweetView = HMHomeRetweetView()
    
}
